<?php declare(strict_types=1);
/**
 * This file is part of Swoft.
 *
 * @link     https://swoft.org
 * @document https://swoft.org/docs
 * @contact  group@swoft.org
 * @license  https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */

/**
 * 获取容器ip标识
 * 如果ip:172.22.22.110,那么返回`172_110`
 */
if (!function_exists('getConsulIpStr')) {
    function getConsulIpStr(): string
    {
        $ip       = env('HOST');
        $ip       = explode('.', $ip);
        $consulIp = $ip[0] . '_' . $ip[3];
        return $consulIp;
    }
}

/**
 * 获取consul服务ID
 */
if (!function_exists('getConsulServerId')) {
    /**
     * @param string $consulIp
     * @return string
     */
    function getConsulServerId($prefix): string
    {
        $hosts = explode('.', env("HOST"));
        return $prefix . '_' . $hosts[0] . '_' . $hosts[3];
    }
}
